package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/13 22:10
 * @Version 1.0
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**使用Collections解決*/
public class Thread0502 {
    public static void main(String[] args) {
        List<String> stringList = Collections.synchronizedList(new ArrayList<>());
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                stringList.add(UUID.randomUUID().toString().substring(0,7));
                System.out.println(stringList);
            },String.valueOf(i)).start();
        }
    }
}
